﻿using System;
using System.Collections.Generic;
using System.Drawing;

namespace Report.Service
{
    public class BitmapOperator
    {
        public static Bitmap Combine(List<Bitmap> bitmaps)
        {
            int height = 0;
            int width = 0;

            foreach (Bitmap bitmap in bitmaps)
            {
                height += bitmap.Height;
                width = Math.Max(width, bitmap.Width);
            }

            var combined = new Bitmap(width, height);

            using (Graphics graphics = Graphics.FromImage(combined))
            {
                int y = 0;
                foreach (Bitmap bitmap in bitmaps)
                {
                    graphics.DrawImage(bitmap, new Rectangle(0, y, combined.Width, bitmap.Height), new Rectangle(0, 0, bitmap.Width, bitmap.Height), GraphicsUnit.Pixel);
                    y += bitmap.Height;
                }
            }

            return combined;
        }
    }
}
